package com.jilefojing.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jilefojing.beans.constant.Constants;
import com.jilefojing.beans.data.response.base.ResponseData;
import com.jilefojing.session.service.ILogoutService;
import com.jilefojing.util.UserTokenUtil;
import com.jilefojing.web.base.BaseWeb;

@Controller
@RequestMapping("logout")
public class LogoutWeb extends BaseWeb {

	private final static Logger _LOGGER = LoggerFactory.getLogger(LogoutWeb.class);

	@Autowired
	private ILogoutService logoutService;

	@RequestMapping("")
	public @ResponseBody ResponseData logout(HttpServletRequest request, HttpServletResponse response) {
		ResponseData baseResponse = new ResponseData();
		try {
			logoutService.logout(UserTokenUtil.getUserTokenFromCookie(request), super.getPlatform());
			request.removeAttribute(Constants.USER_CONTEXT_KEY);
			UserTokenUtil.clearUserTokenFromCookie(request, response);
		} catch (Exception ex) {
			_LOGGER.error("登出异常:" + ex.getMessage());
		}
		return baseResponse;
	}
}
